package com.liuyucheng.idea_springboot.service.impl;

import com.liuyucheng.idea_springboot.dao.EChartsMapper;
import com.liuyucheng.idea_springboot.service.EChartsService;
import com.liuyucheng.idea_springboot.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service
public class EChartsServiceImpl implements EChartsService {

    @Autowired
    private EChartsMapper mapper;

    @Override
    public ResultUtil getDataBar(int id) {
        LinkedHashMap<String, Object> dataBar = mapper.getDataBar(id);
        Map<String,Object> resMap = new HashMap<>();
        resMap.put("key",dataBar.keySet());
        resMap.put("value",dataBar.values());
        return ResultUtil.success(resMap);
    }

    @Override
    public ResultUtil readDs() {
        int res = mapper.readDs();
        return ResultUtil.success(res);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public ResultUtil plusOne() throws Exception {
        List<String> list = new ArrayList<>();
        try {
            int res = mapper.plusOne();
            System.out.println(list.get(9));
            if(res==1){
                return ResultUtil.success("+1成功");
            }
            return ResultUtil.success("操作失败");
        } catch (Exception e) {
            throw new Exception(e);
        }

    }
}
